﻿using Microsoft.AspNetCore.Mvc;

namespace FirstWebAPI;


[Route("api/[controller]")]//告诉下面这个控制器，会匹配这个路由模板
public class UserController : ControllerBase
{
    [HttpGet]//告诉下面这个方法，是通过HTTPget方法请求的
    /// <summary>
    /// 登录
    /// </summary>
    /// <param name="username"></param>
    /// <param name="password"></param>
    /// <returns></returns>
    public bool Login()
    {
        // TODO:业务逻辑实现,
        //Console.WriteLine(username + password);
        var username = Request.Query["username"];
        var password = Request.Query["password"];
        Console.WriteLine(username + password);
        return true;
    }

    [HttpPost("password")]//定义路由的路径是password,而不是下面这个方法名
    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="password"></param>
    /// <returns></returns>
    public async Task<bool> ChangePassword()
    {
        // TODO:业务逻辑实现
        var password = Request.Query["password"];
        //读取流
        using (var reader = new StreamReader(Request.Body))
        {
            var content=await reader.ReadToEndAsync();
            Console.WriteLine(content);
        }
        Console.WriteLine(password);
        return true;
    }

    [HttpGet("login")]
    public bool LoginWithoutParameters()
    {
        var username = Request.Query["username"];
        var password = Request.Query["password"];
        // 其他参数获取...

        // TODO:业务逻辑实现
        Console.WriteLine(username + password);
        return true;
    }
}
